package com.bluedot.www.core.service;


import com.bluedot.www.core.dao.Execute;

import java.util.List;

/**
 * <p>
 * 服务类
 * </p>
 *
 * @author Ding YuXing
 * @since 2021-08-07
 */
public class FeatureStatusService {

    private static final String FEATURESTATUS_MAPPER_ADDRESS = "com.bluedot.www.core.mapper.xml.FeatureStatusMapper.";

    public static Object execute(String methodName, Object[] param) {
        FeatureStatusService featureStatusService = new FeatureStatusService();
        Object result = null;
        switch (methodName) {
            case "activateFeatureByFeatureId":
                result = featureStatusService.activateFeatureByFeatureId((Long) param[0], (Integer) param[1]);
                break;
            case "countFeatureStatus":
                result = featureStatusService.countFeatureStatus();
                break;
            default:
                throw new RuntimeException("Method NOT FOUND, method name: " + methodName);
        }
        return result;
    }

    /**
     * 通过特征id激活特征
     *
     * @param featureId     特征id
     * @param featureStatus 该特征的激活状态 就两种值 一个是0 一个是1
     * @return Boolean
     * @author Ding YuXing
     * @date 2021/8/8 10:32
     */
    private Boolean activateFeatureByFeatureId(Long featureId, Integer featureStatus) {
        if (featureStatus == 0) {
            //接下来要解禁
            Integer Result = (Integer) Execute.execute(Execute.UPDATE_TYPE, FEATURESTATUS_MAPPER_ADDRESS + "activateFeatureByFeatureId", new Object[]{featureId});
            if (Result > 0) {
                return true;
            }
            return false;
        } else {
            //表示接下来要封禁
            Integer Result = prohibitFeatureByFeatureId(featureId);
            if (Result > 0) {
                return true;
            }
            return false;
        }
    }

    private Integer prohibitFeatureByFeatureId(Long featureId) {
        Integer Result = (Integer) Execute.execute(Execute.UPDATE_TYPE, FEATURESTATUS_MAPPER_ADDRESS + "prohibitFeatureByFeatureId", new Object[]{featureId});
        return Result;
    }

    /**
     * 获得笔迹特征数量
     *
     * @return java.lang.Integer 笔迹特征的数量
     * @author He Peng
     * @date 2021/9/8 20:56
     */
    private Integer countFeatureStatus() {
        List<Integer> tmp = (List<Integer>) Execute.execute(Execute.QUERY_TYPE,
                FEATURESTATUS_MAPPER_ADDRESS + "countFeatureStatus", null);
        if (tmp != null && tmp.size() > 0) {
            return tmp.get(0);
        }
        return 0;
    }

}
